<%--

<!--------------------------------------------------------------------------------------------------------------------------------
 - Copyright 2007 CORE Solutions Limited
 - All rights reserved.
 - PROPRIETARY AND CONFIDENTIAL INFORMATION.
 - Use is subject to license terms.
 -
 - FUNCTION ID      :   CATALOG_DTL
 - AUTHOR           :   Saint Peng 
 - DATE CREATE      :   2007/07/17
 - DESCRIPTION      :   a PAGE-EDIT CONTENT JSP file for the function, CATALOG_DTL
 -                  :   
 -                  :   
 -                  :   
 -
 - MODIFICATION HISTORY:
 - DATE         AUTHOR          VERSION NO.         COMMENT
 - -----------  --------------  ------------------  -------------------
 - 2007/07/17   Saint Peng      1.0                 source is generated.
 -
 -
 -
--------------------------------------------------------------------------------------------------------------------------------->

--%>
<%@ include file="/jsp/com/erp/app/common/jsp/directives_include.jsp"%>

<%@ page  import="com.erp.app.catalog.catalogDtl.web.CatalogDtlAction" %>
<%@ page  import="com.erp.app.catalog.catalogDtl.web.CatalogDtlRow" %>

<%@ include file="/jsp/com/erp/app/common/jsp/html_include.jsp"%>

<jsp:useBean id="catalogDtlForm" scope="session" type="com.erp.app.catalog.catalogDtl.web.CatalogDtlForm" />

<%
ArrayList catalogDtlList = catalogDtlForm.getMultiRows();
pageContext.setAttribute("catalogDtlList", catalogDtlList);
rowReadOnly = false;
TableSchema ts = catalogDtlForm.getTs();
%>

<script language="javascript">

	function doLoad() {
		<%
		if (CommonUtil.nullToString((String)session.getAttribute(ProjectConstants.SESSION_ALERT_AFTER_SAVE)).equals(ProjectConstants.GENERIC_YES)) {
			session.removeAttribute(ProjectConstants.SESSION_ALERT_AFTER_SAVE);
			out.println("alert('Records saved.');");
		}
		%>
		<%
		String lastAction = CommonUtil.nullToString(catalogDtlForm.getPageEvent());

		if (lastAction.startsWith(ProjectConstants.ACTION_SPEDIT)) {
			out.println(WebUtil.openSelectRemarkTextDo());
		}
		%>
	}

</script>

<body onLoad="javascript:doLoad();autofill_init();">
<html:form action="/catalogDtl">

<html:hidden property="pageEvent"/>
<html:hidden property="pageEventSrc"/>

<html:hidden property="pageMode"/>
<html:hidden property="deleteIdx"/>

<table class="table_top">

<tr>
	<td>
		<chtml:button form="catalogDtlForm" pageEvent="<%=CatalogDtlAction.ACTION_EXIT%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlForm" pageEvent="<%=CatalogDtlAction.ACTION_SEARCH%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlForm" pageEvent="<%=CatalogDtlAction.ACTION_CLEAR%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlForm" pageEvent="<%=CatalogDtlAction.ACTION_ADD_ROW%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlForm" pageEvent="<%=CatalogDtlAction.ACTION_SAVE%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlForm" pageEvent="<%=CatalogDtlAction.ACTION_REFRESH%>"
			styleClass="button1"/>
	</td>
</tr>

<tr>
	<td>

		<table class="table_crit">
		<tr>
			<%
			webLabel = ts.getDisplayWebLabelWithColonByObjectId("LBL_SRCH_DTL_TYPE");
			%>
			<td class="col_label">
			<%=webLabel%>
			</td>
			<td class="col_value">
				 <%
		       where=" COMPANY_CODE = '"+WebUtil.getAppropriateCompanyCode(session, null) + "' and REF_MASTER_CODE = '"+ ProjectConstants.CD_CATALOG_DTL_TYPE + "'"
			   + " AND REF_STATUS = '"+ProjectConstants.GENERIC_ACTIVE+"' ";
			%>
			<select name="srchHdrDtlTypeFr" <%=formReadOnly ? "disabled=\"true\"" : ""%> class="selectBox1" >
			<option value="" />
			        <chtml:options table="t_code_dtl"
					valuecolumn="REF_CODE"
					textcolumn="REF_DESC"
					where="<%=where%>"
					order="seq, ref_desc"
					selected="<%=CommonUtil.nullToString(catalogDtlForm.getSrchHdrDtlTypeFr())%>" />
			</td>
			
		</tr>
		<tr>
			<%
			webLabel = ts.getDisplayWebLabelWithColonByObjectId("LBL_SRCH_DTL_NAME");
			%>
			<td class="col_label">
			<%=webLabel%>
			</td>
			<td class="col_value">
				<html:text property="srchHdrDtlNameFr" styleClass="textbox1" maxlength="<%=srchColLongSize%>" size="<%=srchDisplayLongSize%>"/>
			</td>
			
		</tr>
		
		<tr>
		<%
			webLabel = ts.getDisplayWebLabelWithColonByObjectId("LBL_SRCH_STATUS");
			%>
			<td class="col_label">
				<html:text useExtensions="true" uiType="label" property="srchHdrStatus" />
			</td>
			<td class="col_value">
				<html:text useExtensions="true"  uiType="combobox" showCode="false" showDescription="true"   property="srchHdrStatus" />
			</td>
		</tr>


		</table>

	</td>
</tr>

<tr>
	<td><font color='red'><html:errors/></font></td>
</tr>

<tr>
	<td class="grid_page">
	<%if(catalogDtlForm.getTotalPage() == 0 ) { %>
		&nbsp;
	<%} else { %>
		<input type="button" value="Go" class="button1" onClick="javascript:doSubmit('<%=catalogDtlForm.ACTION_SCROLL_TO%>');" >
		Page
		<html:text property="scrollTo" styleClass="textbox1" readonly="<%=rowReadOnly%>" maxlength="4" size="4" value="<%=String.valueOf(catalogDtlForm.getCurrentPage())%>"/>
		of <%=catalogDtlForm.getTotalPage()%>
	<%} %>
		<input type="button" value="|&lt;&lt;" class="button1" onClick="javascript:doSubmit('<%=catalogDtlForm.ACTION_SCROLL_TO_FIRST_PAGE%>');" <%=catalogDtlForm.getSidx() == 0 ? "disabled" : ""%>>
		<input type="button" value="&lt;&lt;" class="button1" onClick="javascript:doSubmit('<%=catalogDtlForm.ACTION_SCROLL_LEFT%>');" <%=catalogDtlForm.getSidx() == 0 ? "disabled" : ""%>>
		<input type="button" value="&gt;&gt;" class="button1" onClick="javascript:doSubmit('<%=catalogDtlForm.ACTION_SCROLL_RIGHT%>');" <%=catalogDtlForm.getSidx() < Integer.parseInt(catalogDtlForm.getLastPageSidx()) ? "" : "disabled"%>>
		<input type="button" value="&gt;&gt|" class="button1" onClick="javascript:doSubmit('<%=catalogDtlForm.ACTION_SCROLL_TO_LAST_PAGE%>');" <%=catalogDtlForm.getSidx() < Integer.parseInt(catalogDtlForm.getLastPageSidx()) ? "" : "disabled"%>>
	</td>
</tr>

</table>


<table class="table_grid">

	<tr class="grid_header">
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_DELETE");
		%>
		<td class="grid_header_col_narrow" nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_DTL_ID");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_DTL_TYPE");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_DTL_NAME");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_UOM");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_RECURSIVE_TIME");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_STATUS");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_OPTION_CODE");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
	</tr>

	<logic:iterate id="catalogDtlRow" name="catalogDtlList" indexId="idx" length="<%=String.valueOf(ProjectConstants.MAX_DISPLAY)%>" offset="<%=String.valueOf(catalogDtlForm.getSidx())%>">

	<%
		CatalogDtlRow row = (CatalogDtlRow) catalogDtlRow;
	%>

	<% if((row != null) && (CommonUtil.isEmpty(row.getIsDelete()))) {%>

	<tr <%=(idx.intValue()%2 == 0)? "class='grid_result1'": "class='grid_result2'"%>>
		
		<td nowrap>

			<chtml:button form="catalogDtlForm" deleteButton="true" multiRow="catalogDtlRow" pageEvent="<%=CatalogDtlAction.ACTION_DELETE_ROW%>" pageEventSrc="<%=String.valueOf(idx)%>" styleClass="button1" disabled="<%=String.valueOf(rowReadOnly)%>"/>
		</td>
		<td nowrap>
			<%
			colSize = String.valueOf(ts.getColSizeByObjectId("LBL_GRID_DTL_ID"));
			displaySize = String.valueOf(ts.getDisplaySizeByObjectId("LBL_GRID_DTL_ID"));
			%>
		<bean:write name="catalogDtlRow" property="dtlId" filter="true"/>&nbsp;
		<html:hidden property="dtlId" value="<%=CommonUtil.nullToString(row.getDtlId())%>"/>
		</td>
		
		<td nowrap>
			<%
			colSize = String.valueOf(ts.getColSizeByObjectId("LBL_GRID_DTL_TYPE"));
			displaySize = String.valueOf(ts.getDisplaySizeByObjectId("LBL_GRID_DTL_TYPE"));
			%>
			<logic:equal name="catalogDtlRow" property="rowMode" value="<%=ProjectConstants.ROW_MODE_CREATE%>" >
	        <%
		       where=" COMPANY_CODE = '"+WebUtil.getAppropriateCompanyCode(session, null) + "' and REF_MASTER_CODE = '"+ ProjectConstants.CD_CATALOG_DTL_TYPE + "'"
			   + " AND REF_STATUS = '"+ProjectConstants.GENERIC_ACTIVE+"' ";
			%>
			<select name="hdrDtlType" <%=formReadOnly ? "disabled=\"true\"" : ""%> class="selectBox1" onchange="javascript:doSubmit('doChangeValue');">
			<option value="" />
			        <chtml:options table="t_code_dtl"
					valuecolumn="REF_CODE"
					textcolumn="REF_DESC"
					where="<%=where%>"
					order="seq, ref_desc"
					selected="<%=CommonUtil.nullToString(row.getHdrDtlType())%>" />
			</select>
			</logic:equal>
			<logic:notEqual name="catalogDtlRow" property="rowMode" value="<%=ProjectConstants.ROW_MODE_CREATE%>" >
            <%  where=" COMPANY_CODE = '"+WebUtil.getAppropriateCompanyCode(session, null) + "' and REF_MASTER_CODE = '"+ ProjectConstants.CD_CATALOG_DTL_TYPE + "' and REF_CODE = '" + row.getHdrDtlType() + "'"
			;
			%>
				<chtml:desc table="t_code_dtl"
					column="REF_DESC"
					where="<%=where%>"
				/>
			<html:hidden property="hdrDtlType" value="<%=CommonUtil.nullToString(row.getHdrDtlType())%>"/>
			</logic:notEqual>
		</td>
		<td nowrap>
			<%
			colSize = String.valueOf(ts.getColSizeByObjectId("LBL_GRID_DTL_NAME"));
			displaySize = String.valueOf(ts.getDisplaySizeByObjectId("LBL_GRID_DTL_NAME"));
			%>
			<html:text property="hdrDtlName" styleClass="textbox1" readonly="<%=rowReadOnly%>" maxlength="<%=colSize%>" size="<%=displaySize%>" value="<%=CommonUtil.nullToString(row.getHdrDtlName())%>"/>
		</td>
		<td nowrap>
			<%
			colSize = String.valueOf(ts.getColSizeByObjectId("LBL_GRID_UOM"));
			displaySize = String.valueOf(ts.getDisplaySizeByObjectId("LBL_GRID_UOM"));
			%>
			<%
		       where=" COMPANY_CODE = '"+WebUtil.getAppropriateCompanyCode(session, null) + "' AND ref_master_code = '"+ProjectConstants.CD_MEASUREMENT+ "'"
			   + " AND REF_STATUS = '"+ProjectConstants.GENERIC_ACTIVE+"' ";
			%>					
			<select name="hdrUom" <%=formReadOnly ? "disabled=\"true\"" : ""%> class="selectBox1">
			<option value="" />
			        <chtml:options table="t_code_dtl"
					valuecolumn="REF_CODE"
					textcolumn="ref_desc"
					where="<%=where%>"
					order="seq, ref_desc"
					selected="<%=CommonUtil.nullToString(row.getHdrUom())%>" />
			</select>
		</td>
		<td nowrap>
			<%
			colSize = String.valueOf(ts.getColSizeByObjectId("LBL_GRID_RECURSIVE_TIME"));
			displaySize = String.valueOf(ts.getDisplaySizeByObjectId("LBL_GRID_RECURSIVE_TIME"));
			%>
			<html:text property="hdrRecursiveTime" styleClass="textbox1" readonly="<%=rowReadOnly%>" maxlength="<%=colSize%>" size="<%=displaySize%>" value="<%=CommonUtil.nullToString(row.getHdrRecursiveTime())%>"/>
		</td>
		<td nowrap>
			<%
			colSize = String.valueOf(ts.getColSizeByObjectId("LBL_GRID_STATUS"));
			displaySize = String.valueOf(ts.getDisplaySizeByObjectId("LBL_GRID_STATUS"));
			%>
			<%
	          where =" TYPE = '"+ ProjectConstants.CONSTANT_TYPE_ACT_INACT + "'";
			%>
			<select name="hdrStatus" <%=formReadOnly ? "disabled=\"true\"" : ""%> class="selectBox1">
			<option value="" />
			        <chtml:options table="T_SYS_CONSTANTS"
					valuecolumn="CONSTANT_CODE"
					textcolumn="CONSTANT_NAME"
					where="<%=where%>"					
					selected="<%=CommonUtil.nullToString(row.getHdrStatus())%>" />
			</select>
		</td>
		<td nowrap>
			<%
			colSize = String.valueOf(ts.getColSizeByObjectId("LBL_GRID_OPTION_CODE"));
			displaySize = String.valueOf(ts.getDisplaySizeByObjectId("LBL_GRID_OPTION_CODE"));
			%>
			<%
		        if(ProjectConstants.CATALOG_DTL_TYPE_DORPDOWN.equalsIgnoreCase(row.getHdrDtlType()))
		        {
		          where=" COMPANY_CODE = '"+WebUtil.getAppropriateCompanyCode(session, null) + "'";
		           where +=" and STATUS= '"+ProjectConstants.GENERIC_ACTIVE+"'";
			%>
			<logic:equal name="catalogDtlRow" property="rowMode" value="<%=ProjectConstants.ROW_MODE_CREATE%>" >
			<select name="hdrOptionCode" <%=formReadOnly ? "disabled=\"true\"" : ""%> class="selectBox1">
			<option value="" />
			        <chtml:options table="T_CATALOG_OPTION_HDR"
					valuecolumn="REF_MASTER_CODE"
					textcolumn="REF_DESC"
					where="<%=where%>"					
					selected="<%=CommonUtil.nullToString(row.getHdrOptionCode())%>"/>
			</select>
			</logic:equal>
			<logic:notEqual name="catalogDtlRow" property="rowMode" value="<%=ProjectConstants.ROW_MODE_CREATE%>" >
		     <%  where=" COMPANY_CODE = '"+WebUtil.getAppropriateCompanyCode(session, null) + "'";
		           where +=" and STATUS= '"+ProjectConstants.GENERIC_ACTIVE+"'";
				   where +=" and REF_MASTER_CODE= '"+row.getHdrOptionCode()+"'";

			%>
				<chtml:desc table="T_CATALOG_OPTION_HDR"
					column="REF_DESC"
					where="<%=where%>"
				/>
				<html:hidden property="hdrOptionCode" value="<%=CommonUtil.nullToString(row.getHdrOptionCode())%>"/>
			</logic:notEqual>
			<%} else{ %>
            <html:hidden property="hdrOptionCode" value="<%=CommonUtil.nullToString(row.getHdrOptionCode())%>"/>
			<%}%>
		</td>
	</tr>
 <%} else { %>
		<html:hidden property="isDelete" value="<%=row.getIdx()%>"/>

		<html:hidden property="dtlId" value="<%=CommonUtil.nullToString(row.getDtlId())%>"/>
		<html:hidden property="hdrDtlType" value="<%=CommonUtil.nullToString(row.getHdrDtlType())%>"/>
		<html:hidden property="hdrUom" value="<%=CommonUtil.nullToString(row.getHdrUom())%>"/>
		<html:hidden property="hdrRecursiveTime" value="<%=CommonUtil.nullToString(row.getHdrRecursiveTime())%>"/>
		<html:hidden property="hdrStatus" value="<%=CommonUtil.nullToString(row.getHdrStatus())%>"/>
		<html:hidden property="hdrOptionCode" value="<%=CommonUtil.nullToString(row.getHdrOptionCode())%>"/>
		
	<% } // end if(row != null) %>
      

	<html:hidden property="idx" value="<%=row.getIdx()%>" />
	<html:hidden property="rowMode"  value="<%=row.getRowMode()%>"/>

	</logic:iterate>

</table>

</html:form>
